<?php
namespace App\Console\Commands;

use Illuminate\Console\Command;

class TempCommand extends Command
{
    //命令名
    protected $signature = 'task:dispose';

    //命令描述
    protected $description = '临时处理数据脚本';

    public function __construct()
    {
        parent::__construct();
    }

    //业务处理
    public function handle()
    {
        $timestampRange = [1676822400,1676908800];

//        $t = app('repo_data_statistics')->querySystemSerial(36,$timestampRange);
//        var_dump($t);exit();
        echo time().PHP_EOL;
        $giftIds = app('model_gift')->getGiftIdsByType(36);

        $total = 0;
        for ($i = 0;$i <= 50; $i++){
            $limit = 30000;
            $skip = $i * $limit;
            $gives = app('model_give_gift')->newQuery()
                ->select(['id','gift_id','total_price'])
                ->whereBetween('add_time', $timestampRange)
                ->orderBy('id','asc')
                ->skip($skip)
                ->take($limit)
                ->get();
            if ($gives->isEmpty()){
                unset($gives);
                echo $i.'= break'.PHP_EOL;
                break;
            }
            foreach ($gives as $item){
                if (in_array($item->gift_id,$giftIds)){
                    $total+= $item->total_price;
                }
            }
            unset($gives);
        }
        var_dump($total);
        echo time().PHP_EOL;
    }
}